import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class ToolService {

  constructor() { }

  //级别转换
  levelChange(employee:any) {
    switch(employee.authority) {
      case 0:
        employee.authority = "普通员工";
        break;
      case 1:
        employee.authority = "部门经理";
        break;
      case 2:
        employee.authority = "副总经理";
        break;
      case 3:
        employee.authority = "总经理";
        break;
      case 4:
        employee.authority = "系统管理员";
        break;
    }
  }

  //获取请求body
  getRequestBody(fromBody:any):any {
    let authority;
    switch(fromBody.authority) {
      case '普通员工':
        authority = 0;
        break;
      case '部门经理':
        authority = 1;
        break;
      case '副总经理':
        authority = 2;
        break;
      case '总经理':
        authority = 3;
        break;
      case '系统管理员':
        authority = 4;
        break;        
    }

    let requestBody = {
      eid: fromBody.eid,
      name: fromBody.name,
      gender: fromBody.gender,
      password: fromBody.password,
      phone: fromBody.phone,
      authority: authority,
      annualleave: Number(fromBody.annualleave)
    }

    return requestBody;
  }
  
}
